package org.datascooter.meta;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MetaColumn implements Serializable {

	private static final long serialVersionUID = -8903322080065516315L;
	public final String TABLE_CAT;
	public final String TABLE_SCHEM;
	public final String TABLE_NAME;
	public final String COLUMN_NAME;
	public final int DATA_TYPE;
	public final String TYPE_NAME;
	public final int COLUMN_SIZE;
	public final int DECIMAL_DIGITS;
	public final boolean NULLABLE;
	public final String REMARKS;
	public final String COLUMN_DEF;
	public final int CHAR_OCTET_LENGTH;
	public final int ORDINAL_POSITION;
	public final boolean IS_NULLABLE;
	private DataTypeInfo dataTypeInfo;

	public MetaColumn(ResultSet rs) throws SQLException {
		TABLE_CAT = rs.getString("TABLE_CAT");
		TABLE_SCHEM = rs.getString("TABLE_SCHEM");
		TABLE_NAME = rs.getString("TABLE_NAME");
		COLUMN_NAME = rs.getString("COLUMN_NAME");
		DATA_TYPE = rs.getInt("DATA_TYPE");
		TYPE_NAME = rs.getString("TYPE_NAME");
		COLUMN_SIZE = rs.getInt("COLUMN_SIZE");
		DECIMAL_DIGITS = rs.getInt("DECIMAL_DIGITS");
		if (rs.getInt("NULLABLE") == 0)
			NULLABLE = false;
		else
			NULLABLE = true;
		REMARKS = rs.getString("REMARKS");
		COLUMN_DEF = rs.getString("COLUMN_DEF");
		CHAR_OCTET_LENGTH = rs.getInt("CHAR_OCTET_LENGTH");
		ORDINAL_POSITION = rs.getInt("ORDINAL_POSITION");
		if (rs.getString("IS_NULLABLE").equalsIgnoreCase("NO"))
			IS_NULLABLE = false;
		else
			IS_NULLABLE = true;
	}

	public void setDataTypeInfo(DataTypeInfo dataTypeInfo) {
		this.dataTypeInfo = dataTypeInfo;
	}

	public DataTypeInfo getDataTypeInfo() {
		return dataTypeInfo;
	}
}
